package mn.slide.labmed.info;

import mn.slide.labmed.R;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;

public class BenutzActivity extends Activity
{

	private Button	zuruck;

	@Override
	public void onCreate( Bundle savedInstanceState )
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.benuts);

		// Benutztxt
		WebView mWebView = (WebView) findViewById(R.id.benutsWV);
		mWebView.setVerticalScrollBarEnabled(false);
		mWebView.setScrollContainer(false);
		String text = "<html><head> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></head><body>" + "<p align=\"justify\"><font>" + fixString(getString(R.string.benutstxt)) + "</font></p> " + "</body></html>";
		WebSettings webSettings = mWebView.getSettings();
		webSettings.setDefaultFontSize(15);
		mWebView.setBackgroundColor(0);
		mWebView.setBackgroundResource(R.drawable.background);
		mWebView.loadData(text, "text/html", "utf-8");

		zuruck = (Button) findViewById(R.id.zuruckbenutz);

		zuruck.setOnClickListener(new View.OnClickListener()
		{

			public void onClick( View v )
			{
				InfoTabGroupActivity.group.back();
			}
		});

		EditText searchbox = (EditText) findViewById(R.id.benuz_search);
		searchbox.setOnKeyListener(new View.OnKeyListener()
		{

			public boolean onKey( View v , int keyCode , KeyEvent event )
			{
				if (keyCode == KeyEvent.KEYCODE_ENTER)
				{
					EditText searchbox = (EditText) v;
					InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
					imm.hideSoftInputFromWindow(searchbox.getWindowToken(), 0);
					InfoTabGroupActivity.group.goSearchActivity(searchbox.getText().toString());
				}
				return false;
			}
		});
	}

	private String fixString( String str )
	{
		String ans = "";
		for (int i = 0; i < str.length(); i++)
			if (str.charAt(i) == '\n')
			{
				ans += "<br>";
			}
			else
				ans += str.charAt(i);
		return ans;
	}

}
